<?php

 class Word{
 	
 	public $data;
 	private $name;
    private $ftp;
    private $dir;
    private $recordTime;
    
 	public function __construct($data , $name , $type , $dateName = ""){
 		if (count($data) == 0) exit; 	
 		$this->recordTime = $dateName;	
 		$this->name = $name;
 		$this->dir = "./";
 		$this->data = $data;
		$type == 0 ? $this->summary() : $this->projectReply();
 		$this->outHTTP();

 	}
 	
 	//计算第几周
 	private function getFileDate(){
		 	$date = $this->recordTime;
 		    $day = date("N" , strtotime($date));
		    $d['e'] = date("Y-m-d" , strtotime($date)+(7-$day)*24*60*60);
		    $d['s'] = date("Y-m-d" , strtotime($date)-($day-1)*24*60*60);
		    $d['d'] = date("Y" , strtotime($date));
		    $d['a'] = date("Y-m-d");
			$d['m'] = date("W",strtotime($date));
			return $d;
 	}
 	
 	//生成工作报告
	public function summary(){
	  $date = $this->getFileDate();
	  $str =  '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>';
	  $str .= '<body style="margin:0"><table width="90%" align="center" border="1" bordercolor="#000000" ';
	  $str .= ' style="border-collapse:collapse; margin:0">'."\n";	  
	  $str .= '<tr><td colspan="2" align="center">起始日期：'.$date["s"].' 至 '.$date["e"].'</td>';
	  $str .= '<td align="center">编号：'.$date["d"].'年 '.$date["m"].'周</td></tr>';
	  $str .= '<tr><th>姓名</th><th>工作总结</th><th>工作计划</th></tr>';
	  foreach ($this->data as $value){
	    $str .= '<tr><th align="left" width="90">'.$value[0].'</th>';
	    $str .= '<td width="46%">'.$value[1].'</td>';
	    $str .='<td valign="top">'.$value[2].'</td></tr>';     
	  }
	  $str .="</table></body></html>";
      $this->date = $str;
	}
    
	
	//生成业务跟进情况
	public function projectReply(){
	  $str =  '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body style="margin:0">';
	  $str .= '<h2 align="center">'.$this->recordTime.'('.count($this->data).')</h2>';
	  $str .= '<table width="90%" align="center" border="1" bordercolor="#000000"  style="border-collapse:collapse">'."\n";	  
	  foreach ($this->data as $value){
	    $str .= '<tr><td align="left" style="padding:5px"><br />'.$value[2];
		$str .= '<br/><br/><br/><div align="right" style="margin:5px 20px 5px 0">[姓名：'.$value[0].']&nbsp;&nbsp;';
		$str .= '[时间：'.$value[1].']</div></td></tr>';
	  }
	  $str .="</table></body></html>";
      $this->date = $str;	  
	}
 	
	//输出http文件流 
	public function outHTTP(){
		Header("Content-type:  application/octet-stream"); 
		Header("Content-Disposition:   attachment;   filename=".$this->name);  
		echo $this->date;
	}
	
 }

?>